﻿using System;
using System.Collections.Generic; 
using System.Text;
using ATSModel;
using ATSIDAL;
 

namespace ATSBLL
{
    public class TPackage : BaseService<TPackageInfo>
    {
        private static readonly ITPackage dal = DALFactory.DataAccess.CreateTPackage();
        private static readonly ITTest tTest =  DALFactory.DataAccess.CreateTTest();
        private static readonly IPIMTest pIMTest = DALFactory.DataAccess.CreatePIMTset();
        
        
        public override void SetCurrentRepository()
        {
            CurrentRepository = dal;
        }

  
        /// <summary>
        /// 上传包装数据
        /// </summary> 
        /// <param name="tp">实体类</param>
        /// <param name="str">提示信息</param>
        /// <returns>bool</returns>
        public bool UploalPackageData(TPackageInfo tp)
        {
            TPackage tPackage = new TPackage();
            #region 注释代码
            //if (!IsRASN(RSN, ASN, out str)) //判断追溯条码和天线条码是否已存在 
            //{
            //    return false;
            //}
            //else if (!IsRASN(RSN, ASN, out str)) //检测条码是否符合规则
            //{
            //    return false;
            //}
            //else if (!IsPass(RSN, ASN, out str))//测试数据是否合格
            //{
            //    return false;
            //}
            //else if (!ASN.Equals(OBSN) ||!ASN.Equals(OCSN))  //判断天线 外箱 外罩 条码是否一致
            //{
            //    str = "天线,外箱，外罩条码不一致！";
            //    return false;
            //}
            #endregion
            //上传包装数据  
            try
            {
                tPackage.Insert(tp);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        } 

        /// <summary> 
        ///追溯条码和天线条码是否已存在 
        /// </summary>
        /// <param name="var_RSN">追溯条码</param> 
        /// <returns>bool</returns>
        public bool IsRASN(string RSN)
        {
            if (!string.IsNullOrEmpty(dal.GetRetrospectSN(RSN).RetrospectSN))
            {
                return true;
            }     
            return false;
        }

        /// <summary> 
        ///天线条码是否已存在 
        /// </summary>
        /// <param name="var_ASN">天线条码</param> 
        /// <returns>bool</returns>
        public bool IsASN(string ASN)
        {
            if (!string.IsNullOrEmpty(dal.GetAntennaSN(ASN).ProductSN))
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 根据条码检索包装信息
        /// </summary>
        /// <param name="SN"></param>
        /// <returns></returns>
        public IList<TPackageInfo> GetPackInfoBySN(string SN) 
        {
            return dal.GetPackInfoBySN(SN);
        }


        /// <summary>
        /// 根据时间检索包装信息
        /// </summary>
        /// <param name="starttime"></param>
        /// <param name="stoptime"></param>
        /// <returns></returns>
        public IList<TPackageInfo> GetPackInfobyDT(DateTime starttime, DateTime stoptime) 
        {
            return dal.GetPackInfobyDT(starttime,stoptime);
        
        }

        /// <summary>
        /// 根据产品类型检索包装信息
        /// </summary>
        /// <param name="PType"></param>
        /// <returns></returns>
        public IList<TPackageInfo> GetPackInfoByPType(string PType) 
        {
            return dal.GetPackInfoByPType(PType);
        }


        /// <summary>
        /// 根据产品编号检索包装
        /// </summary>
        /// <param name="productSN"></param>
        /// <returns></returns>
        public TPackageInfo ProductSN_IsPackage(string productSN)
        {
            return dal.ProductSN_IsPackage(productSN);
        }

        public IList<TPackageInfo> IsPackageBySN(string productSN)
        {
            return dal.IsPackageBySN(productSN);
        }
         

        
    }
}